package patrol.mobile.com.mobilepatrol.activity.security.emergency;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.activity.security.ConsTitles;
import patrol.mobile.com.mobilepatrol.bean.ProtectListBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.widget.MySpinner;

/**
 * Created by fuzhen.li on 2018/9/18.
 */
public class EmergencyPackageSignInActivity extends BaseActivity {
    @BindView(R.id.tv_signIn)
    TextView tvSignIn;
    @BindView(R.id.spSigin)
    MySpinner spSigin;

    private List<ProtectListBean> protectListBeanList = new ArrayList<>();
    private List<String> singInList = new ArrayList<>();
    private String id = "";
    private String holderId ="";
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_emergency_package_sign_in;
    }

    @Override
    public void setListener() {
        spSigin.setmDatas(singInList, new MySpinner.CallBack() {
            @Override
            public void onSelect(int postion) {
                String people = singInList.get(postion);
                synchronized (this) {
                    for (int i = 0; i < protectListBeanList.size(); i++) {
                        if (protectListBeanList.get(i).getHouseholder().equals(people)) {
                            id = protectListBeanList.get(i).getId();
                            holderId = protectListBeanList.get(i).getHolderId();
                        }
                    }
                }
            }
        });
    }

    @Override
    public void initData() {
        super.initData();
        Intent intent = getIntent();
        if (intent != null) {
            protectListBeanList = (List<ProtectListBean>) intent.getSerializableExtra("sigin");
            for (int i = 0; i < protectListBeanList.size(); i++) {
                singInList.add(protectListBeanList.get(i).getHouseholder());
            }

        }

    }

    @Override
    public void initTitle() {
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(EmergencyPackageSignInActivity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText(ConsTitles.EMERGENCY_PACKAGE_SIGN_IN);
    }


    @OnClick({R.id.tv_signIn})
    public void onSignClick(View v) {

        switch (v.getId()) {

            case R.id.tv_signIn:
                synchronized (this) {
                    for (int i = 0; i < protectListBeanList.size(); i++) {
                        if (protectListBeanList.get(i).getHouseholder().equals( spSigin.getmText().getText().toString())) {
                            id = protectListBeanList.get(i).getId();
                            holderId = protectListBeanList.get(i).getHolderId();
                        }
                    }
                }
                Intent intent = new Intent(this, EmergencyPeopleInfoActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("holderId",holderId);
                startActivity(intent);
                break;

        }

    }

}
